package com.jspgou.cms.entity;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import com.jspgou.cms.entity.base.BaseRole;

public class Role extends BaseRole {
	private static final long serialVersionUID = 1L;
	
	 public static Long[] fetchIds(Collection<Role> roles) {
			if (roles == null) {
				return null;
			}
			Long[] ids = new Long[roles.size()];
			int i = 0;
			for (Role r : roles) {
				ids[i++] = r.getId();
			}
			return ids;
		}

/*[CONSTRUCTOR MARKER BEGIN]*/
	public Role () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Role (java.lang.Long id) {
		super(id);
	}

	/**
	 * Constructor for required fields
	 */
	public Role (
		java.lang.Long id,
		com.jspgou.cms.entity.Store store,
		java.lang.String name,
		java.lang.Integer priority,
		java.lang.Boolean m_super,
		java.lang.Boolean noedit) {

		super (
			id,
			store,
			name,
			priority,
			m_super,
			noedit);
	}
	
	/**
	 * 添加至角色
	 * 
	 * @param tag
	 */
	public void addToMembers(ShopMember member) {
		Set<ShopMember> set =getMembers();
		if (set == null) {
			set = new HashSet<ShopMember>();
			setMembers(set);
		}
		set.add(member);
	}
	
	/**
	 * 添加权限
	 * 
	 * @param tag
	 */
	public void addToPerms(Set<String> perms) {
		Set<String> set =getPerms();
		if (set == null) {
			set = new HashSet<String>();
			setPerms(set);
		}
			set.addAll(perms);
	}
	
	/**
	 * 删除权限
	 */
	public void removePerms() {
		Set<String> set =getPerms();
		if (set == null) {
			set = new HashSet<String>();
			setPerms(set);
		}else{
			set.clear();
		}
		
	}

/*[CONSTRUCTOR MARKER END]*/


}